home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / WUNZ20SR.ZIP / ABOUT.C next >
C/C++ Source or Header  |  1993-03-24  |  2KB  |  81 lines

  1. #include <windows.h>    /* required for all Windows applications */
  2.  
  3.  
  4. /*
  5.  -      CenterDialog
  6.  -      
  7.  *      Purpose:
  8.  *              Moves the dialog specified by hwndDlg so that it is centered on
  9.  *              the window specified by hwndParent. If hwndParent is null,
  10.  *              hwndDlg gets centered on the screen.
  11.  *      
  12.  *              Should be called while processing the WM_INITDIALOG message
  13.  *              from the dialog's DlgProc().
  14.  *      
  15.  *      Arguments:
  16.  *              HWND    parent hwnd
  17.  *              HWND    dialog's hwnd
  18.  *      
  19.  *      Returns:
  20.  *              Nothing.
  21.  *      
  22.  */
  23. void
  24. CenterDialog(HWND hwndParent, HWND hwndDlg)
  25. {
  26.         RECT    rectDlg;
  27.         RECT    rect;
  28.         int             dx;
  29.         int             dy;
  30.  
  31.         if (hwndParent == NULL)
  32.         {
  33.                 rect.top = rect.left = 0;
  34.                 rect.right = GetSystemMetrics(SM_CXSCREEN);
  35.                 rect.bottom = GetSystemMetrics(SM_CYSCREEN);
  36.         }
  37.         else
  38.         {
  39.                 GetWindowRect(hwndParent, &rect);
  40.         }
  41.  
  42.         GetWindowRect(hwndDlg, &rectDlg);
  43.         OffsetRect(&rectDlg, -rectDlg.left, -rectDlg.top);
  44.  
  45.         dx = (rect.left + (rect.right - rect.left -
  46.                         rectDlg.right) / 2 + 4) & ~7;
  47.         dy = rect.top + (rect.bottom - rect.top -
  48.                         rectDlg.bottom) / 2;
  49.         MoveWindow(hwndDlg, dx, dy, rectDlg.right, rectDlg.bottom, 0);
  50. }
  51.  
  52.  
  53. /****************************************************************************
  54.  
  55.     FUNCTION: About(HWND, unsigned, WORD, LONG)
  56.  
  57.     PURPOSE:  Processes messages for "About" dialog box
  58.  
  59.     MESSAGES:
  60.  
  61.     WM_INITDIALOG - initialize dialog box
  62.     WM_COMMAND    - Input received
  63.  
  64. ****************************************************************************/
  65.  
  66. BOOL FAR PASCAL
  67. AboutProc(HWND hwndDlg, WORD wMessage, WORD wParam, LONG lParam)
  68. {
  69.     if ((wMessage == WM_CLOSE) || 
  70.         (wMessage == WM_COMMAND && wParam == IDOK))
  71.         EndDialog(hwndDlg, TRUE);
  72.  
  73.     if (wMessage == WM_INITDIALOG)
  74.     {
  75.             CenterDialog(GetParent(hwndDlg), hwndDlg);
  76.     }
  77.     return ((wMessage == WM_CLOSE) || (wMessage == WM_INITDIALOG) || (wMessage == WM_COMMAND))
  78.             ? TRUE : FALSE;
  79. }
  80.  
  81.